home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-21 | 3.3 KB | 118 lines | [TEXT/MPS ] |
- (*
- TCPPassiveOpen(remoteIP,remotePort,localPort) -- Open a TCP connection to the socket specified, and
- return the connection ID.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w TCPActiveOpen.p
- link -m ENTRYPOINT -o HyperCommands -rt XFCN=7861 -sn Main=TCPActiveOpen ∂
- TCPActiveOpen.p.o "{Libraries}HyperXLib.o" "{MPW}"Libraries:interface.o
-
- © Copyright 1988 by Apple Computer, Inc.
-
- Initial coding 12/88 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S TCPPassiveOpen } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure TCPPassiveOpen(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- TCPPassiveOpen(paramPtr);
- end;
-
- procedure TCPPassiveOpen(paramPtr: XCmdPtr);
-
- var remoteIP: longInt; { IP address of desintation. }
- remotePort: integer; { Port address of destination. }
- localPort: integer; { Port address on our side. }
- dummy: integer;
- resultStr: str255;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(TCPPassiveOpen);
- end;
-
- {$I TCPUtil.inc}
-
- procedure FailAndDispose(errMsg: Str255);
- begin
- DisposPtr(Ptr(Connection));
- Fail(errMsg)
- end;
-
- procedure createStream;
- { Make a new stream. }
-
- begin
- { Allocate our info block. }
- Connection := TCPConnectionPtr(NewPtr(sizeof(TCPConnectionType)));
- if Connection = nil then Fail('§§§ buffer allocation failed §§§');
- Connection^.magic := MAGICNUMBER;
- Connection^.incomingSize := 0;
- { Open the driver. }
- if OpenDriver('.IPP',SyncControlBlock.ioCRefNum) <> noErr then
- FailAndDispose('§§§ driver open failed §§§');
- { Create a new stream. }
- ZeroIOParms;
- PutControlLongAtOffset(ord4(@Connection^.buffer),32);
- PutControlLongAtOffset(TCPBUFFERSIZE,36);
- SyncControlBlock.csCode := TCPcsCreate;
- if PBControl(@SyncControlBlock,false) <> noErr then
- FailAndDispose('§§§ stream creation failed §§§');
- Connection^.asyncControlBlock := SyncControlBlock;
- end;
-
- begin
- if (paramPtr^.paramCount <> 2) and (paramPtr^.paramCount <> 3) then
- Fail('§§§ parameter count is not 2 or 3 §§§');
-
- remoteIP := GetLongParm(1); { First parameter is the remote IP address. }
- remotePort := GetLongParm(2); { Second parameter is the remote port number. }
- if paramPtr^.paramCount = 3 then localPort := GetLongParm(3) { Third parameter is the local port #. }
- else localPort := 0; { ... which is optional. }
-
- { Make a new stream. }
- createStream;
-
- { Issue the passive open. }
- ZeroIOParms;
- PutControlLongAtOffset(remoteIP,36);
- PutControlWordAtOffset(remotePort,40);
- PutControlWordAtOffset(localPort,46);
- with Connection^ do
- begin
- SyncControlBlock.csCode := TCPcsPassiveOpen;
- asyncControlBlock := SyncControlBlock;
- if PBControl(@asyncControlBlock,true) <> noErr then
- begin
- ZeroIOParms;
- SyncControlBlock.csCode := TCPcsRelease;
- dummy := PBControl(@SyncControlBlock,false);
- FailAndDispose('§§§ connection open failed §§§');
- end;
- end;
-
- { Return the connection ID. }
- LongToStr(paramPtr,Ord4(Connection),resultStr);
- paramPtr^.returnValue := PasToZero(paramPtr,resultStr)
- end;
-
- end.
-